# -*- coding: utf-8 -*-
"""

PBAR_ConvertNumpyFilestoPickle
Created on Thu May 08 09:48:21 2014

@author: jkwong
"""


import cPickle, glob, os, shutil
import numpy as np


dirIn = r'E:\PBAR\data4\BasicScansStandardWidth'
dirOut = r'E:\PBAR\data4\BasicScansStandardWidthPickle'

filelist = glob.glob(os.path.join(dirIn, '*.npy'))

for fIndex, f in enumerate(filelist):
    if (fIndex % 100 == 0):
        print(fIndex)
    if f.find('.cargomarkerSW.npy') > 0:
        a, b = os.path.split(f)
        filenameOutput = os.path.join(dirOut, b.replace('.cargomarkerSW.npy', '.cargomarkerSW'))
        shutil.copy(f, filenameOutput)
        continue
    
    a, b = os.path.split(f)
    dat = np.load(f)
    with open(os.path.join(dirOut, b.replace('.npy', '.dat')), 'wb') as fid:
        cPickle.dump(dat, fid, 2)
    